//
//  AddMemberView.m
//  HAODE
//
//  Created by panquanReabam.com on 16/5/20.
//  Copyright © 2016年 reabam.com. All rights reserved.
//

#import "AddMemberView.h"
#import "UIAlertView+show.h"
#import "TagView.h"
@interface AddMemberView()<UITextFieldDelegate,UIGestureRecognizerDelegate,UIScrollViewDelegate,UITextViewDelegate>

@property (nonatomic,weak) id delegate;
@property(nonatomic,retain)UIDatePicker* da;
@property(nonatomic,retain)UIDatePicker* da1;
@end
@implementation AddMemberView

{
    NSString*isDefault;
    BOOL saveAccount;
    UIImageView* ima;
    UILabel*labelNote;
    TagView*tagV;
    UIView* myToolBar;
    UIButton* ToObtain;
    UILabel*tagLebal;
    UILabel*noteLebal;
    UILabel*babyInformationLebal;
    UIView*p006View;
    UILabel* verification;
    UIButton*zhankai;
    UIButton*dueDatebtn;
    UIButton*birthDateBtn;
    UILabel *line8;
     NSMutableArray*funNameArray;
}
@synthesize alt = alt;
@synthesize mDelegate;
#pragma mark LifeCycle
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self initUI];
    }
    return self;
}
#pragma mark InitUI
- (void)initUI
{
    self.backgroundColor=[UIColor whiteColor];
    myToolBar=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, viewheight)];
    myToolBar.backgroundColor=jianpancolor;
    UIButton*  tubtnDone=[[UIButton alloc]initWithFrame:CGRectMake(logoX,logoY, logoheight, logowidth)];
    [tubtnDone setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
    [tubtnDone addTarget:self action:@selector(OnTapDone) forControlEvents:UIControlEventTouchUpInside];
    [myToolBar addSubview:tubtnDone];
    UIButton*btnDone111=[[UIButton alloc]initWithFrame:CGRectMake(myToolBar.frame.size.width - 55, 12, 40, 16)];
    [btnDone111 setTitle:@"确定" forState:UIControlStateNormal];
    [btnDone111 setTitleColor:jianpancolor1 forState:UIControlStateNormal];
    btnDone111 .titleLabel .font=[UIFont systemFontOfSize:keyboardFot];
    [btnDone111 addTarget:self action:@selector(OnTapDone) forControlEvents:UIControlEventTouchUpInside];
    [myToolBar addSubview:btnDone111];
    myToolBar.alpha=alp;
    UIButton* dabtn=[[UIButton alloc]initWithFrame:CGRectMake(myToolBar.frame.size.width-60, 0, 60, 40)];
    [dabtn addTarget:self action:@selector(OnTapDone) forControlEvents:UIControlEventTouchUpInside];
    [myToolBar addSubview:dabtn];
    
    _myscrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0,0, ScreenWidth, ScreenHeight)];
    [_myscrollView setBackgroundColor: zuiqianhuiColor];
    _myscrollView.delegate = self;
    _myscrollView.userInteractionEnabled = YES;
    _myscrollView.scrollEnabled = YES;
    _myscrollView.showsVerticalScrollIndicator = FALSE;
    _myscrollView.showsHorizontalScrollIndicator = FALSE;
    
    UITapGestureRecognizer *singleFingerOne = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(OnTapDone)];
    singleFingerOne.numberOfTouchesRequired = 1; //手指数
    singleFingerOne.numberOfTapsRequired = 1; //tap次数
    singleFingerOne.delegate = self;
    [_myscrollView addGestureRecognizer:singleFingerOne];
    
    UIView*view1=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 88/2)];
    view1.backgroundColor=[UIColor whiteColor];
    [_myscrollView addSubview:view1];
    
    UIView*view2=[[UIView alloc]initWithFrame:CGRectMake(0, 88/2+10, ScreenWidth, 88/2*7)];
    view2.backgroundColor=[UIColor whiteColor];
    [_myscrollView addSubview:view2];
    UILabel* duogou=[[UILabel alloc]initWithFrame:CGRectMake(20,0, 40, 44)];
    duogou.text=[NSString stringWithFormat:@"导购"];
    duogou.textColor=shenhuiColor;
    duogou.font=[UIFont systemFontOfSize:15];
    [_myscrollView addSubview:duogou];
    
    NSUserDefaults *user1 = [NSUserDefaults standardUserDefaults];
    NSString* userName = [user1 objectForKey:@"userName"];
    //   self.GuideCode = [user1 objectForKey:@"UserCode"];
    UIButton*daogouname=[[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth-200,  0,180,44)];
    [daogouname setTitle:userName forState:UIControlStateNormal];
    daogouname.titleLabel.font=[UIFont systemFontOfSize:15];
    daogouname.titleLabel.textAlignment=NSTextAlignmentLeft;
    daogouname.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
    [daogouname setTitleColor:shenhuiColor forState:UIControlStateNormal];
    [_myscrollView addSubview:daogouname];
    
    UIView*huiseview=[[UIView alloc]initWithFrame:CGRectMake(0,44, ScreenWidth, 10)];
    huiseview.backgroundColor=zuiqianhuiColor;
    huiseview.layer.borderWidth = 0.40;
    huiseview.layer.borderColor = qianhuiColor.CGColor;
    [_myscrollView addSubview:huiseview];
    
    
    UILabel* WeChatId=[[UILabel alloc]initWithFrame:CGRectMake(20, 88/2+10, 70,44)];
    WeChatId.text=[NSString stringWithFormat:@"%@", @"微信昵称"];
    WeChatId.font=[UIFont systemFontOfSize:15];
    WeChatId.textColor=shenhuiColor;
    [_myscrollView addSubview:WeChatId];
    
    _weChatIdTextFied=[[UITextField alloc]initWithFrame:CGRectMake(WeChatId.right, 89/2+10, 150, 44)];
    _weChatIdTextFied.borderStyle = UITextBorderStyleNone;
    _weChatIdTextFied.font = [UIFont systemFontOfSize:15];
    _weChatIdTextFied.textColor=qianheiColor;
    _weChatIdTextFied.autocapitalizationType = UITextAutocapitalizationTypeSentences;
    _weChatIdTextFied.tag=1;
    _weChatIdTextFied.placeholder = @"请获取微信昵称"; //默认显示的字
    [_weChatIdTextFied setUserInteractionEnabled:NO];
    _weChatIdTextFied.clearButtonMode = UITextFieldViewModeWhileEditing;
    [_myscrollView addSubview:_weChatIdTextFied];
    
    UIButton* QrCodeBtn=[[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth-60,  88/2+20, 30,30)];
    [QrCodeBtn setBackgroundImage:[UIImage imageNamed:@"gongzhonghaoerweima"]  forState:UIControlStateNormal];
    [QrCodeBtn addTarget:self action:@selector(QrCodeBtn:) forControlEvents:UIControlEventTouchUpInside];
    [_myscrollView addSubview: QrCodeBtn];
    
    UILabel* UserName1=[[UILabel alloc]initWithFrame:CGRectMake(20, 88/2+10+44, 70,88/2)];
    UserName1.text=[NSString stringWithFormat:@"%@", @"姓名"];
    UserName1.textColor=shenhuiColor;
    UserName1.font=[UIFont systemFontOfSize:15];
    [_myscrollView addSubview:UserName1];
    _userNameTextFied=[[UITextField alloc]initWithFrame:CGRectMake(WeChatId.right,  88/2+10+44, ScreenWidth-115-70,  88/2)];
    _userNameTextFied.borderStyle = UITextBorderStyleNone;
    _userNameTextFied.font = [UIFont systemFontOfSize: 15];
    _userNameTextFied.textColor=qianheiColor;
    _userNameTextFied.autocapitalizationType = UITextAutocapitalizationTypeSentences;
    _userNameTextFied.tag=2;
    _userNameTextFied.placeholder = @"请输入会员姓名"; //默认显示的字
    _userNameTextFied.delegate = self;
    [_userNameTextFied setUserInteractionEnabled:YES];
    _userNameTextFied.clearButtonMode = UITextFieldViewModeWhileEditing;
    [_myscrollView addSubview:_userNameTextFied];
    _da1 = [[UIDatePicker alloc] init];
    [_da1 addTarget:self action:@selector(dateChanged1:) forControlEvents:UIControlEventValueChanged];
    _da1.datePickerMode = UIDatePickerModeDate;
    _da1.backgroundColor=[UIColor whiteColor];
    UILabel* birthDate=[[UILabel alloc]initWithFrame:CGRectMake(20, 44*2+10+44, 70,88/2)];
    birthDate.text=[NSString stringWithFormat:@"%@", @"生日"];
    birthDate.textColor=shenhuiColor;
    birthDate.font=[UIFont systemFontOfSize:15];
    [_myscrollView addSubview:birthDate];
    
    _birthDateTextFied=[[UITextField alloc]initWithFrame:CGRectMake(WeChatId.right,  44*2+10+44,ScreenWidth,  88/2)];
    _birthDateTextFied.borderStyle = UITextBorderStyleNone;
    _birthDateTextFied.font = [UIFont systemFontOfSize: 15];
    _birthDateTextFied.textColor=qianheiColor;
    _birthDateTextFied.autocapitalizationType = UITextAutocapitalizationTypeSentences;
    _birthDateTextFied.tag=11;
    _birthDateTextFied.placeholder = @"请选择生日日期"; //默认显示的字
    _birthDateTextFied.delegate = self;
    _birthDateTextFied.inputView = _da1;
    _birthDateTextFied.inputAccessoryView= myToolBar;
    [_myscrollView addSubview:_birthDateTextFied];
    birthDateBtn = [[UIButton alloc]init];
    birthDateBtn.frame = CGRectMake(ScreenWidth-40,44*2+17+44,33, 33);
    birthDateBtn.userInteractionEnabled=NO;
    [birthDateBtn setImage:[UIImage imageNamed:@"zhankai"] forState:UIControlStateNormal];
    [_myscrollView addSubview:birthDateBtn];
    
    
    
    UILabel* Phone=[[UILabel alloc]initWithFrame:CGRectMake(15, 44*3+10+44, 70,88/2)];
    Phone.text=[NSString stringWithFormat:@"%@", @"*手机号码"];
    Phone.textColor=shenhuiColor;
    NSMutableAttributedString *AttributedStr = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"%@", @"*手机号码"]];
    [AttributedStr addAttribute:NSForegroundColorAttributeName
     
                          value:hongseColor
     
                          range:NSMakeRange(0, 1)];
    Phone.attributedText = AttributedStr;
    Phone.font=[UIFont systemFontOfSize:15];
    [_myscrollView addSubview:Phone];
    _phoneTextFied=[[UITextField alloc]initWithFrame:CGRectMake(WeChatId.right,  44*3+10+44, ScreenWidth-115,  88/2)];
    _phoneTextFied.borderStyle = UITextBorderStyleNone;
    _phoneTextFied.keyboardType = UIKeyboardTypeNumberPad;
    _phoneTextFied.font = [UIFont systemFontOfSize: 15];
    _phoneTextFied.textColor=qianheiColor;
    _phoneTextFied.autocapitalizationType = UITextAutocapitalizationTypeSentences;
    _phoneTextFied.tag=3;
    _phoneTextFied.placeholder = @"请输入会员手机号码"; //默认显示的字
    _phoneTextFied.delegate = self;
    [_phoneTextFied addTarget:self action:@selector(userNumberLimitTextLength:) forControlEvents:UIControlEventEditingChanged];
    [_phoneTextFied setUserInteractionEnabled:YES];
    _phoneTextFied.clearButtonMode = UITextFieldViewModeWhileEditing;
    [_myscrollView addSubview:_phoneTextFied];
    
    
    
    UILabel* verification1=[[UILabel alloc]initWithFrame:CGRectMake(15, 44*4+10+44, 70,88/2)];
    verification1.text=[NSString stringWithFormat:@"%@", @"*验证码"];
    verification1.textColor=shenhuiColor;
    NSMutableAttributedString *AttributedStr2 = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"%@", @"*验证码"]];
    [AttributedStr2 addAttribute:NSForegroundColorAttributeName
     
                           value:hongseColor
     
                           range:NSMakeRange(0, 1)];
    verification1.attributedText = AttributedStr2;
    
    verification1.font=[UIFont systemFontOfSize:15];
    [_myscrollView addSubview:verification1];
    _verificationCode = [[UITextField alloc] initWithFrame:CGRectMake(WeChatId.right, 44*4+10+44, ScreenWidth-115-100, 44)];
    [_verificationCode setBorderStyle:UITextBorderStyleNone]; //外框类型
    _verificationCode.placeholder = @"请输入手机验证码"; //默认显示的
    _verificationCode.font = [UIFont systemFontOfSize: 15];
    _verificationCode.autocorrectionType = UITextAutocorrectionTypeNo;
    _verificationCode.autocapitalizationType = UITextAutocapitalizationTypeNone;
    _verificationCode.returnKeyType = UIReturnKeyDone;
    _verificationCode.clearButtonMode = UITextFieldViewModeWhileEditing; //编辑时会出现个修改X
    _verificationCode.delegate = self;
    _verificationCode.tag=6;
    _verificationCode.textColor=qianheiColor;
    _verificationCode.keyboardType = UIKeyboardTypeDecimalPad;
    [_myscrollView addSubview:_verificationCode];
    _verificationCode.inputAccessoryView = myToolBar;
    ToObtain = [[UIButton alloc] initWithFrame:CGRectMake(ScreenWidth-90-15, 44*4+10+44+7.5, 90,30)];
    [ToObtain setTitle:@"获取验证码" forState:UIControlStateNormal];
    ToObtain.titleLabel.font = [UIFont systemFontOfSize: 13.0];
    [ToObtain.layer setCornerRadius:2];
    [ToObtain.layer setBorderWidth:0.35];
    [ToObtain.layer setMasksToBounds:YES];
    CGColorSpaceRef tureBTnSpace = CGColorSpaceCreateDeviceRGB();
    CGColorRef tureBTncolorref = CGColorCreate(tureBTnSpace,(CGFloat[]){204/255.0, 204/255.0, 204/255.0, 1.0});
    [ToObtain.layer setBorderColor:tureBTncolorref];//边框颜色
    [ToObtain setTitleColor:[UIColor colorWithRed:249/255.0 green:53/255.0 blue:30/255.0 alpha:1.0]
                   forState:UIControlStateNormal];
    [ToObtain addTarget:self action:@selector(startTime) forControlEvents:UIControlEventTouchUpInside];
    [_myscrollView addSubview:ToObtain];
    

    UILabel* ProvinceName=[[UILabel alloc]initWithFrame:CGRectMake(20, 44*5+10+44, 70,88/2)];
    ProvinceName.text=[NSString stringWithFormat:@"%@", @"地区"];
    ProvinceName.font=[UIFont systemFontOfSize:15];
    ProvinceName.textColor=shenhuiColor;
    [_myscrollView addSubview:ProvinceName];
    UIButton*area=[[UIButton alloc]initWithFrame:CGRectMake(ProvinceName.right, 44*5+10+45, ScreenWidth, 88/2)];
    [area addTarget:self action:@selector(area:) forControlEvents:UIControlEventTouchUpInside];
    [_myscrollView addSubview:area];
    zhankai = [[UIButton alloc]init];
    zhankai.frame = CGRectMake(ScreenWidth-40,44*5+14+47,33, 33);
    [zhankai addTarget:self action:@selector(area:) forControlEvents:UIControlEventTouchUpInside];
    [zhankai setImage:[UIImage imageNamed:@"zhankai"] forState:UIControlStateNormal];
    [_myscrollView addSubview:zhankai];
    
    _regionTextField=[[UITextField alloc]initWithFrame:CGRectMake(WeChatId.right,  44*5+10+44, 150, 88/2)];
    _regionTextField.borderStyle = UITextBorderStyleNone;
    _regionTextField.font = [UIFont systemFontOfSize: 15];
    _regionTextField.textColor=qianheiColor;
    _regionTextField.autocapitalizationType = UITextAutocapitalizationTypeSentences;
    _regionTextField.tag=4;
    _regionTextField.placeholder = @"请选择地区"; //默认显示的字
    [_regionTextField setUserInteractionEnabled:NO];
    _regionTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
    [_myscrollView addSubview:_regionTextField];
    
    
    
    UILabel* Address=[[UILabel alloc]initWithFrame:CGRectMake(20, 44*6+10+44, 70,88/2)];
    Address.text=[NSString stringWithFormat:@"%@", @"收货地址"];
    Address.font=[UIFont systemFontOfSize:15];
    Address.textColor=shenhuiColor;
    [_myscrollView addSubview:Address];
    _addressTextFied=[[UITextField alloc]initWithFrame:CGRectMake(WeChatId.right, 44*6+10+44, ScreenWidth-115,  88/2)];
    _addressTextFied.borderStyle = UITextBorderStyleNone;
    _addressTextFied.font = [UIFont systemFontOfSize: 15];
    _addressTextFied.textColor=qianheiColor;
    _addressTextFied.autocapitalizationType = UITextAutocapitalizationTypeSentences;
    _addressTextFied.tag=5;
    _addressTextFied.placeholder = @"请输入详细地址"; //默认显示的字
    [_addressTextFied setUserInteractionEnabled:YES];
    _addressTextFied.delegate = self;
    _addressTextFied.clearButtonMode = UITextFieldViewModeWhileEditing;
    [_myscrollView addSubview:_addressTextFied];
    
    
    
    UILabel *line1 = [[UILabel alloc]initWithFrame:CGRectMake(10,88/2+10+44, ScreenWidth-20, 0.40)];
    line1.backgroundColor = qianhuiColor;
    [_myscrollView addSubview:line1];
    UILabel *line2 = [[UILabel alloc]initWithFrame:CGRectMake(10,88+10+44, ScreenWidth-20, 0.40)];
    line2.backgroundColor = qianhuiColor;
    [_myscrollView addSubview:line2];
    UILabel *line3 = [[UILabel alloc]initWithFrame:CGRectMake(10,88/2*3+10+44, ScreenWidth-20, 0.40)];
    line3.backgroundColor = qianhuiColor;
    [_myscrollView addSubview:line3];
    UILabel *line4 = [[UILabel alloc]initWithFrame:CGRectMake(10,88/2*4+10+44, ScreenWidth-20, 0.40)];
    line4.backgroundColor = qianhuiColor;
    [_myscrollView addSubview:line4];
    UILabel *line5 = [[UILabel alloc]initWithFrame:CGRectMake(10,88/2*5+10+44, ScreenWidth-20, 0.40)];
    line5.backgroundColor = qianhuiColor;
    [_myscrollView addSubview:line5];
    UILabel *line6 = [[UILabel alloc]initWithFrame:CGRectMake(10,88/2*6+10+44, ScreenWidth-20, 0.40)];
    line6.backgroundColor = qianhuiColor;
    [_myscrollView addSubview:line6];
    UILabel *line7 = [[UILabel alloc]initWithFrame:CGRectMake(10,88/2*7+10+44-0.40, ScreenWidth-20, 0.40)];
    line7.backgroundColor = qianhuiColor;
    [_myscrollView addSubview:line7];
    
    _regionTextField.inputAccessoryView = myToolBar;
    _addressTextFied.inputAccessoryView = myToolBar;
    _phoneTextFied.inputAccessoryView = myToolBar;
    _userNameTextFied.inputAccessoryView = myToolBar;
    [self addSubview:_myscrollView];
    
}
-(void)startTime{
    
    if ([_phoneTextFied.text length]<1)
    {
        [self showAlertMessage:@"请输入手机号码"];
    }else{
        if ([_phoneTextFied.text length]!=11)
        {
            [self showAlertMessage:@"手机位数有误"];
        }else{
            
            __block int timeout=60; //倒计时时间
            dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
            dispatch_source_t _timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0,queue);
            dispatch_source_set_timer(_timer,dispatch_walltime(NULL, 0),1.0*NSEC_PER_SEC, 0); //每秒执行
            dispatch_source_set_event_handler(_timer, ^{
                if(timeout<=0){ //倒计时结束，关闭
                    dispatch_source_cancel(_timer);
                    dispatch_async(dispatch_get_main_queue(), ^{
                        //设置界面的按钮显示 根据自己需求设置
                        [ToObtain setTitle:@"获取" forState:UIControlStateNormal];
                        ToObtain.userInteractionEnabled = YES;
                    });
                }else{
                    //            int minutes = timeout / 60;
                    int seconds = timeout % 60;
                    NSString *strTime = [NSString stringWithFormat:@"%.2d", seconds];
                    dispatch_async(dispatch_get_main_queue(), ^{
                        //设置界面的按钮显示 根据自己需求设置
                        //                NSLog(@"____%@",strTime);
                        if (strTime.intValue==59) {
                            NSLog(@"____%@",strTime);
                            NSMutableDictionary *params = [NSMutableDictionary new];
                            [params setValue:_phoneTextFied.text forKey:@"mobile"];
                            [params setValue:@"M" forKey:@"msgType"];
                            [HttpRequest requestData:@"System/SendMsg" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
                                if (isSuccess) {
                                    NSLog(@"====%@",severDataDict.dataDict);
                                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                                        [Global hideProgressHUDInternal:self];
                                        //                                        NSString*ResultString=[severDataDict.dataDict objectForKey:@"ResultString"];
                                        //                                        [self showAlertMessage:ResultString];
                                        
                                    }else{
                                        [Global hideProgressHUDInternal:self];
                                    }}
                                else
                                {
                                    [Global hideProgressHUDInternal:self];
                                    [Global showTextHudSub:severDataDict.resultStr view:self];
                                }
                            }];
                        }
                        
                        if (![strTime isEqualToString:@"00"]) {
                            [ToObtain setTitle:[NSString stringWithFormat:@"%@秒重获",strTime] forState:UIControlStateNormal];
                            
                        }
                        ToObtain.userInteractionEnabled = NO;
                        
                    });
                    timeout--;
                    
                }
            });
            dispatch_resume(_timer);
        }
    }
}
-(void)setModel:(TagModel *)model{
    NSLog(@"=======%@",model.selectTagNameArray);
    funNameArray=[[NSMutableArray alloc]init];
     [p006View removeFromSuperview];
    [_noteAddTagView removeFromSuperview];
    
    _noteAddTagView=[[UIView alloc]initWithFrame:CGRectMake(0, 44*7+44, ScreenWidth, 88)];
    _noteAddTagView.backgroundColor=[UIColor whiteColor];
   [_myscrollView addSubview:_noteAddTagView];
    line8 = [[UILabel alloc]initWithFrame:CGRectMake(0,88-0.40, ScreenWidth, 0.40)];
    line8.backgroundColor = qianhuiColor;
    [_noteAddTagView addSubview:line8];

    UIButton*tagLabel=[[UIButton alloc]initWithFrame:CGRectMake(20, 0, ScreenWidth, 44)];
    [tagLabel setTitle:@"标签" forState:UIControlStateNormal];
    tagLabel.titleLabel.font= [UIFont systemFontOfSize:15];
    tagLabel.contentHorizontalAlignment=UIControlContentHorizontalAlignmentLeft;
    [tagLabel addTarget:self action:@selector(SelectTag:) forControlEvents:UIControlEventTouchUpInside];
    [tagLabel setTitleColor:shenhuiColor forState:UIControlStateNormal];
    [_noteAddTagView addSubview:tagLabel];
    UIButton*btn=[[UIButton alloc]init];
    btn.frame=CGRectMake(ScreenWidth-40, tagLabel.bottom-44+6, 33, 33);
    [btn setImage:[UIImage imageNamed:@"shouqi"] forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(SelectTag:) forControlEvents:UIControlEventTouchUpInside];
    [_noteAddTagView addSubview:btn];
    
    UILabel*lineLabel=[[UILabel alloc]initWithFrame:CGRectMake(10, tagLabel.bottom, ScreenWidth-20, 0.40)];
    lineLabel.backgroundColor=qianhuiColor;
    [_noteAddTagView addSubview:lineLabel];
    
    tagLebal=[[UILabel alloc]initWithFrame:CGRectMake(ScreenWidth-200, 0, 165, 44)];
    tagLebal.font= [UIFont systemFontOfSize:15];
    tagLebal.textColor=hongseColor;
    tagLebal.textAlignment=NSTextAlignmentRight;
    tagLebal.text=[NSString stringWithFormat:@"已选择%ld个",  (unsigned long)model.selectTagNameArray.count];
    [_noteAddTagView addSubview:tagLebal];
    if (model.selectTagNameArray.count>0) {
        UIImageView *_hengxian = [[UIImageView alloc]initWithFrame:CGRectMake(10,tagLabel.bottom, ScreenWidth-20, 0.5)];
        _hengxian.image=[UIImage imageNamed:@"hengxian"];
        [_noteAddTagView addSubview:_hengxian];
        for (int i = 0,j = 0; i < model.selectTagNameArray.count; i++) {
            if (i % 4 == 0) {
                j++;
            }
            tagV = [[TagView alloc]initWithFrame:CGRectMake(12.5+(ScreenWidth/4-5)*(i%4), (31*j)+tagLebal.bottom-20, ScreenWidth/4-15, 25)];
            tagV.buttonView.titleLabel.textAlignment=NSTextAlignmentCenter;
            tagV.buttonView.titleLabel.font=[UIFont systemFontOfSize:contenfot];
            [tagV.buttonView setTitle: [model.selectTagNameArray objectAtIndex:i]  forState:UIControlStateNormal];
            CGColorSpaceRef colorSpace2 = CGColorSpaceCreateDeviceRGB();
            CGColorRef colorref2 = CGColorCreate(colorSpace2,(CGFloat[]){209/255.0,170/255.0, 56/255.0, 1.0   });
            tagV.buttonView.backgroundColor=[UIColor colorWithRed:255/255.0 green:250/255.0 blue:234/255.0 alpha:1];
            [tagV.buttonView.layer setBorderColor:colorref2];//边框颜色
            [tagV.buttonView setTitleColor:[UIColor colorWithRed:207/255.0 green:170/255.0 blue:68/255.0 alpha:1] forState:0];
            [_noteAddTagView addSubview:tagV];
            
        }
        lineLabel.frame=CGRectMake(10, tagV.bottom+10, ScreenWidth-20, 0.40);
    }else{
        tagLebal.text=@"请选择标签";
        tagLebal.frame=CGRectMake(90, 0, 150, 44);
        tagLebal.textColor= [UIColor colorWithRed:204/255.0 green:204/255.0 blue:204/255.0 alpha:1];
        tagLebal.textAlignment=NSTextAlignmentLeft;
    }
    
    
    UIButton*note=[[UIButton alloc]initWithFrame:CGRectMake(20, lineLabel.bottom, ScreenWidth, 44)];
    [note setTitle:@"备注" forState:UIControlStateNormal];
    note.titleLabel.font= [UIFont systemFontOfSize:15];
    note.contentHorizontalAlignment=UIControlContentHorizontalAlignmentLeft;
    [note addTarget:self action:@selector(note:) forControlEvents:UIControlEventTouchUpInside];
    [note setTitleColor:shenhuiColor forState:UIControlStateNormal];
    [_noteAddTagView addSubview:note];
    _noteLabel=[[UITextField alloc]initWithFrame:CGRectMake(90, lineLabel.bottom, ScreenWidth-115, 44)];
    _noteLabel.font= [UIFont systemFontOfSize:15];
    _noteLabel.textColor=qianheiColor;
    _noteLabel.placeholder = @"请输入备注"; //默认显示的字
    [_noteLabel setUserInteractionEnabled:NO];
    [_noteAddTagView addSubview:_noteLabel];
    UILabel*lineLabel1=[[UILabel alloc]initWithFrame:CGRectMake(10, note.bottom, ScreenWidth-20, 0.40)];
    lineLabel1.backgroundColor=zuiqianhuiColor;
    [_noteAddTagView addSubview:lineLabel1];
    UIButton*renzhenButton=[[UIButton alloc]init];
    renzhenButton.frame=CGRectMake(ScreenWidth-40, note.bottom-44+6, 33, 33);
    [renzhenButton setImage:[UIImage imageNamed:@"shouqi"] forState:UIControlStateNormal];
    [renzhenButton addTarget:self action:@selector(note:) forControlEvents:UIControlEventTouchUpInside];
    [_noteAddTagView addSubview:renzhenButton];
    UIButton*Btn=[[UIButton alloc]init];
    Btn.backgroundColor=[UIColor clearColor];
    Btn.frame=CGRectMake(0, note.bottom, ScreenWidth, 44);
    [Btn addTarget:self action:@selector(note:) forControlEvents:UIControlEventTouchUpInside];
    [_noteAddTagView addSubview:Btn];
    _noteAddTagView.frame=CGRectMake(0, 44*7+10+44, ScreenWidth, note.bottom);
    line8.frame=CGRectMake(0, note.bottom-0.40, ScreenWidth, 0.40);

   
    p006View=[[UIView alloc]initWithFrame:CGRectMake(0, _noteAddTagView.bottom+10, ScreenWidth, 0)];
    p006View.backgroundColor=[UIColor whiteColor];
    p006View.layer.borderWidth = 0.40;
    p006View.layer.borderColor = qianhuiColor.CGColor;
    [_myscrollView addSubview:p006View];
    
    [verification removeFromSuperview];
    verification=[[UILabel alloc]initWithFrame:CGRectMake(20, p006View.bottom+10, 170,88/2)];
    verification.text=[NSString stringWithFormat:@"%@", @"带 ＊ 为必填项"];
    verification.font=[UIFont systemFontOfSize:15];
    verification.textColor=hongseColor;
    [_myscrollView addSubview:verification];
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSMutableArray* funConfigs = [user objectForKey:@"funConfigs"];
    [funNameArray removeAllObjects];
    if (funConfigs.count>0) {
        for (NSDictionary* dicc in funConfigs )
        {
            if ( [[NSString stringWithFormat:@"%@",[dicc valueForKey:@"display"] ]isEqualToString:@"1"]&&[[NSString stringWithFormat:@"%@",[dicc valueForKey:@"funCode"]]isEqualToString:@"member_moreinfo_baby"] ) {
                [funNameArray addObject:@"宝宝信息"];
            
            }
//            else if ([[NSString stringWithFormat:@"%@",[dicc valueForKey:@"display"] ]isEqualToString:@"1"]&&[[NSString stringWithFormat:@"%@",[dicc valueForKey:@"funCode"]]isEqualToString:@"member_moreinfo_yuchanqi"]){
//                [funNameArray addObject:@"预产期"];
//            }
        
        }
        
    }
    
        for (int i = 0; i<funNameArray.count; i++) {
            
            if ([[NSString stringWithFormat:@"%@",funNameArray[i]]isEqualToString:@"宝宝信息"]) {
                UIButton *buchongxinxi = [UIButton buttonWithType:UIButtonTypeCustom];
                buchongxinxi.frame = CGRectMake(0, 15, 18, 18);
                [buchongxinxi setBackgroundImage:[UIImage imageNamed:@"buchongxinxi"] forState:UIControlStateNormal];
                [p006View addSubview:buchongxinxi];
                UIButton*bu=[[UIButton alloc]initWithFrame:CGRectMake(20,0, ScreenWidth, 50)];
                [bu setTitle:@"补充信息" forState:UIControlStateNormal];
                bu.titleLabel.font= [UIFont systemFontOfSize:15];
                bu.contentHorizontalAlignment=UIControlContentHorizontalAlignmentLeft;
                [bu setTitleColor:luseColor forState:UIControlStateNormal];
                [p006View addSubview:bu];

                UIButton*babyInformation=[[UIButton alloc]initWithFrame:CGRectMake(20, 50, ScreenWidth, 50)];
                [babyInformation setTitle:@"宝宝信息" forState:UIControlStateNormal];
                babyInformation.titleLabel.font= [UIFont systemFontOfSize:15];
                babyInformation.contentHorizontalAlignment=UIControlContentHorizontalAlignmentLeft;
                [babyInformation addTarget:self action:@selector(babyInformation:) forControlEvents:UIControlEventTouchUpInside];
                [babyInformation setTitleColor:shenhuiColor forState:UIControlStateNormal];
                [p006View addSubview:babyInformation];
                UILabel*lineLabel11=[[UILabel alloc]initWithFrame:CGRectMake(10, babyInformation.bottom, ScreenWidth-20, 0.40)];
                lineLabel11.backgroundColor=qianhuiColor;
                [p006View addSubview:lineLabel11];
                UILabel *lineLabel12=[[UILabel alloc] initWithFrame:CGRectMake(10, babyInformation.bottom+50-0.40, ScreenWidth-20, 0.40)];
                lineLabel12.backgroundColor=qianhuiColor;
                [p006View addSubview:lineLabel12];
                UIButton*babyInformationBtn=[[UIButton alloc]init];
                babyInformationBtn.frame=CGRectMake(ScreenWidth-40, babyInformation.bottom-50+8, 33, 33);
                [babyInformationBtn setImage:[UIImage imageNamed:@"shouqi"] forState:UIControlStateNormal];
                [babyInformationBtn addTarget:self action:@selector(babyInformation:) forControlEvents:UIControlEventTouchUpInside];
                [p006View addSubview:babyInformationBtn];
    
                UILabel*ts=[[UILabel alloc]initWithFrame:CGRectMake(90,  50, ScreenWidth-90,  50)];
                ts.font = [UIFont systemFontOfSize: 15];
                ts.text = @"请选择宝宝信息"; //默认显示的字
                ts.textColor=[UIColor colorWithRed:204/255.0 green:204/255.0 blue:204/255.0 alpha:1];
                [p006View addSubview:ts];

                if (_babyInformationArray.count>0) {
                    ts.textColor=[UIColor clearColor];
                    for (int i = 0; i < _babyInformationArray.count; i++) {
                        if (i<3) {
                            babyInformationLebal=[[UILabel alloc]initWithFrame:CGRectMake((ScreenWidth-(i+1)*95)-40, 50, 95, 50)];
                            babyInformationLebal.font= [UIFont systemFontOfSize:13];
                            babyInformationLebal.textColor=qianheiColor;
                            babyInformationLebal.textAlignment=NSTextAlignmentCenter;
                            if ([[NSString stringWithFormat:@"%@",  [_babyInformationArray[i]objectForKey:@"name"]]length]>0) {
                                babyInformationLebal.text=[NSString stringWithFormat:@"%@%@",  [_babyInformationArray[i]objectForKey:@"name"], [self getUTCFormateDate: [_babyInformationArray[i]objectForKey:@"birthDate"]]];
                            }
    
                            [p006View addSubview:babyInformationLebal];
                        }
    
                    }
                }
    
    
                _da = [[UIDatePicker alloc] init];
                [_da addTarget:self action:@selector(dateChanged:) forControlEvents:UIControlEventValueChanged];
                _da.datePickerMode = UIDatePickerModeDate;
                _da.backgroundColor=[UIColor whiteColor];
    
    
                UIButton*dueDate=[[UIButton alloc]initWithFrame:CGRectMake(20, babyInformation.bottom, ScreenWidth, 50)];
                [dueDate setTitle:@"预产期" forState:UIControlStateNormal];
                dueDate.titleLabel.font= [UIFont systemFontOfSize:15];
                dueDate.contentHorizontalAlignment=UIControlContentHorizontalAlignmentLeft;
                [dueDate setTitleColor:shenhuiColor forState:UIControlStateNormal];
                [p006View addSubview:dueDate];
               dueDatebtn=[[UIButton alloc]init];
                dueDatebtn.frame=CGRectMake(ScreenWidth-40, dueDate.bottom-50+9, 33, 33);
                [dueDatebtn setImage:[UIImage imageNamed:@"zhankai"] forState:UIControlStateNormal];
                [p006View addSubview:dueDatebtn];
                _dueDateTextFied=[[UITextField alloc]initWithFrame:CGRectMake(90,  babyInformation.bottom, ScreenWidth-90,  50)];
                _dueDateTextFied.borderStyle = UITextBorderStyleNone;
                _dueDateTextFied.font = [UIFont systemFontOfSize: 15];
                _dueDateTextFied.textColor=qianheiColor;
                _dueDateTextFied.placeholder = @"请选择预产时间"; //默认显示的字
                _dueDateTextFied.text= @"";
                _dueDateTextFied.tag=5;
                _dueDateTextFied.delegate = self;
                [p006View addSubview:_dueDateTextFied];
                _dueDateTextFied.inputView = _da;
                _dueDateTextFied.inputAccessoryView= myToolBar;
        
                p006View.frame=CGRectMake(0, _noteAddTagView.bottom+10, ScreenWidth, 150);
            }else{
                p006View.frame=CGRectMake(0, _noteAddTagView.bottom+10, ScreenWidth, 0);
               
            }
        }
    
        verification .frame=CGRectMake(20, p006View.bottom, ScreenWidth, 44);
       [_myscrollView setContentSize:CGSizeMake(ScreenWidth, verification.bottom+200)];
    
    
    
    
    
}
-(void)dateChanged1:(UIButton*)sender{
    UIDatePicker* picker = (UIDatePicker*)sender;
    NSDateFormatter* df = [[NSDateFormatter alloc] init];
    [df setDateFormat:@"yyyy-MM-dd"];
    if ([_birthDateTextFied isFirstResponder])
    {
        _birthDateTextFied.text = [NSString stringWithFormat:@"%@", [df stringFromDate:picker.date]];
        
    }else{
        
        _birthDateTextFied.text = [NSString stringWithFormat:@"%@", [df stringFromDate:picker.date]];
    }
}
-(void)dateChanged:(UIButton*)sender{
    UIDatePicker* picker = (UIDatePicker*)sender;
    NSDateFormatter* df = [[NSDateFormatter alloc] init];
    [df setDateFormat:@"yyyy-MM-dd"];
    if ([_dueDateTextFied isFirstResponder])
    {
        _dueDateTextFied.text = [NSString stringWithFormat:@"%@", [df stringFromDate:picker.date]];
        
    }else{
        
        _dueDateTextFied.text = [NSString stringWithFormat:@"%@", [df stringFromDate:picker.date]];
    }
}

- (void)textFieldDidEndEditing:(UITextField *)textField{
    if (textField.tag==5) {
        if (textField.text.length<1) {
            NSDateFormatter* df = [[NSDateFormatter alloc] init];
            [df setDateFormat:@"yyyy-MM-dd"];
            _dueDateTextFied.text = [NSString stringWithFormat:@"%@", [df stringFromDate:[NSDate date]]];
        }
    }else  if(textField.tag==11){
    
        if (textField.text.length<1) {
            NSDateFormatter* df = [[NSDateFormatter alloc] init];
            [df setDateFormat:@"yyyy-MM-dd"];
            _birthDateTextFied.text = [NSString stringWithFormat:@"%@", [df stringFromDate:[NSDate date]]];
        }
    }
}

-(void)babyInformation:(UIButton *)sender{
    [mDelegate babyInformatio:@""];
    
}
-(void)note:(UIButton *)sender{
    [mDelegate remarkBtn:@""];
    
}
-(void)SelectTag:(UIButton *)sender{
    
    [mDelegate tagBtn:@""];
}
-(void)QrCodeBtn:(UIButton *)sender{
    [mDelegate QrCodeBtn:@""];
}
-(void)area:(UIButton *)sender{
    [self OnTapDone];
    [zhankai setImage:[UIImage imageNamed:@"shouqi_shang"] forState:UIControlStateNormal];
    [mDelegate area:@""];
    
}

//账号长度限制
- (void)userNumberLimitTextLength:(UITextField*)textField
{
    [mDelegate cancelLocatePicker:@""];
    if ([textField.text length] > 11)
    {
        textField.text = [textField.text substringToIndex:11];
    }
}
- (void)textFieldDidBeginEditing:(UITextField *)textField{
    [zhankai setImage:[UIImage imageNamed:@"zhankai"] forState:UIControlStateNormal];
    [mDelegate cancelLocatePicker:@""];
    if (textField.tag == 5)
    {
          [dueDatebtn setImage:[UIImage imageNamed:@"shouqi_shang"] forState:UIControlStateNormal];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
        _myscrollView .frame =CGRectMake(0, -200, ScreenWidth, ScreenHeight);
        [UIView commitAnimations];
    }else if (textField.tag==11){
     [birthDateBtn setImage:[UIImage imageNamed:@"shouqi_shang"] forState:UIControlStateNormal];
    
    }
    
}


-(void)textViewDidChange:(UITextView *)textView
{
    
    if (textView.text.length == 0) {
        [ima removeFromSuperview];
        ima=[[UIImageView alloc]initWithFrame:CGRectMake(10, 8, 51/3, 51/3)];
        ima.image=[UIImage imageNamed:@"_0000_xingxifankui.png"];
        labelNote.text = @"备注";
    }else{
        [ima removeFromSuperview];
        labelNote.text = @"";
    }
}


//回收键盘
-(void)OnTapDone
{
    [_birthDateTextFied resignFirstResponder];
    [_verificationCode resignFirstResponder];
    [_addressTextFied resignFirstResponder];
    [_regionTextField resignFirstResponder];
    [_phoneTextFied resignFirstResponder];
    [_userNameTextFied resignFirstResponder];
    [ _dueDateTextFied resignFirstResponder];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
    _myscrollView .frame =CGRectMake(0, 0, ScreenWidth, ScreenHeight);
    [UIView commitAnimations];
    [zhankai setImage:[UIImage imageNamed:@"zhankai"] forState:UIControlStateNormal];
    [dueDatebtn setImage:[UIImage imageNamed:@"zhankai"] forState:UIControlStateNormal];
    [birthDateBtn setImage:[UIImage imageNamed:@"zhankai"] forState:UIControlStateNormal];
    [mDelegate cancelLocatePicker:@""];
}
- (void)showAlertWait
{
    alt = [[UIAlertView alloc] initWithTitle:@"网络不稳定 ！" message:@"请确认网络" delegate:self cancelButtonTitle:nil otherButtonTitles: nil];
    [alt show];
    
    [self performSelector:@selector(hideAlert) withObject:nil afterDelay:1.0f];
    
}
- (void)showAlertMessage:(NSString *)msg
{
    alt = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:msg delegate:nil cancelButtonTitle:nil otherButtonTitles: nil];
    [alt show];
    
    [self performSelector:@selector(hideAlert) withObject:nil afterDelay:1.0f];
}
- (void)hideAlert
{
    if (alt != nil)
    {
        [alt dismissWithClickedButtonIndex:0 animated:YES];
        alt = nil;
    }
}
-(NSString *)getUTCFormateDate:(NSString *)newsDate
{
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd"];
    NSDate *newsDateFormatted = [dateFormatter dateFromString:newsDate];
    NSTimeZone *timeZone = [NSTimeZone timeZoneWithName:@"UTC"];
    [dateFormatter setTimeZone:timeZone];
    NSDate* current_date = [[NSDate alloc] init];
    NSTimeInterval time=[current_date timeIntervalSinceDate:newsDateFormatted];//间隔的秒数
    int month=((int)time)/(3600*24*30);
    int days=((int)time)/(3600*24);
    NSString *dateMonth;
    if(month!=0){
        dateMonth = [NSString stringWithFormat:@"%d岁",month];
    }else if(days!=0){
        //31天以下还是显示0月
        //        dateMonth = [NSString stringWithFormat:@"%d%@",days,@"天"];
        dateMonth = [NSString stringWithFormat:@"%@%@",@"0",@"个月"];
    }
    
    if (month/12>=1) {
        int dateYear=month/12;
        int dateYear1=month%12;
        dateMonth = [NSString stringWithFormat:@"%d岁%d个月",dateYear,dateYear1];
        
    }else{
        int dateYear1=month%12;
        dateMonth = [NSString stringWithFormat:@"%d个月",dateYear1];
        
    }
    
    return dateMonth;
}@end
